#include <iostream>
#include"head.h"
void menu8(Node* phead)
{
	while(1)
	{
		system("cls"); 
		printf("\n工资计算\n");
    	printf("-------------------------------------\n");
    	printf("               菜单                  \n");
		printf("           1.计算个人月工资\n"); 
		printf("           2.计算部门月工资\n"); 
		printf("           3.计算全校月工资\n");
		printf("           0.退出\n"); 
		printf("-------------------------------------\n");
		printf("请选择（0-3）");
		char option[0];
		while(1){

			scanf("%s", &option);
			if(option[0]>='0'&&option[0]<='3'){
				break;
			}
			else{
				printf("输入错误，重新输入0-3\n");
			}
		}

		int choice;
		choice = option[0]-'0';
		system("cls");
		switch(choice)
		{
    		case 0:
			{
				return ;
			}
			
			case 1:
			{
				calculate_Employee(phead);
				break;
			}
			
			case 2:
			{
				calculate_Employee(phead);
				
				char str[20];
				printf("输入部门：");
				scanf("%s",str);
				
				double n=0;
				Node* p = phead->next;
				while(p != NULL)
				{
					calculate_department(p->data, str, &n);
		
					p = p->next;
				}
				
				printf("%s部门对应月工资%lf", str, n);
				break;
			}
			
			case 3:
			{
				double n=0;
				Node* p = phead->next;
				while(p != NULL)
				{
					Employee* E = (Employee*)p->data;
					
					n = n + E->net_payroll;
					
					p = p->next;
				}
				
				printf("全校对应月工资%lf", n);
				
				break;
			}
			
			default: continue;
				
    	}
    	system("pause");
    }
}

void calculate_Employee(Node* phead)
{
	void (*pFunc2)(void*data);
	pFunc2 = calculate;
	
	Traversal(phead, pFunc2);
	
}

void calculate(void* data)//计算工资
{
	Employee* E = (Employee*)data; 

	E->net_payroll = E->base_pay + E->job_subisidy + E->escalsting_wage + E->wage_sttached_to_a_post + E->housing_add - E->chummage + E->ovrtime_pay + E->night_duty_allowance - E->sick_leave_deduction - E->personal_leave_deduction - E->absenteism_deduction - E->other_deductions;
	
	return;
} 

void calculate_department(void*data, char str[20], double*n)
{
	Employee* E = (Employee*)data;

	if(strcmp(E->department,str) == 0)
	{
		*n = *n + E->net_payroll;
	}

	return;
	
}